package com.newcoder.controller;


import com.newcoder.service.impl.DataServiceImpl;
import com.newcoder.util.ResponseWrapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/data")
public class DataController {

    @Autowired
    private DataServiceImpl dataService;

    @ApiOperation("统计网站UV")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start",value = "开始时间"),
            @ApiImplicitParam(name = "end",value = "结束时间"),
    })
    @PostMapping("/calculateUV")
    public ResponseWrapper calculateUV(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                        @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {
        ResponseWrapper wrapper = dataService.calculateUV(start, end);
        return wrapper;
    }

    @ApiOperation("统计活跃用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "start",value = "开始时间"),
            @ApiImplicitParam(name = "end",value = "结束时间"),
    })
    @PostMapping("/calculateDAU")
    public ResponseWrapper calculateDAU(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                       @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {
        ResponseWrapper wrapper = dataService.calculateDAU(start, end);
        return wrapper;
    }

}
